package com.h819.core.utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

public class PrintFormatHelper {

	public static String Format(Object[] array) {
		if (array == null || array.length == 0) {
			return "[]";
		}
		StringBuffer ret = new StringBuffer("[");
		
		int length = array.length;	
		for (int i = 0; i < length; i++) {
			ret.append(array[i] + ",");
		}
		ret.setCharAt(ret.length() - 1, ']');
		return ret.toString();
	}

	public static String Format(Collection collection) {
		if (collection == null || collection.isEmpty()) {
			return "[]";
		}
		return Format(collection.toArray());
	}

	public static String Format(Map map) {
		if (map == null || map.isEmpty()) {
			return "[]";
		}
		Object key = null;
		StringBuffer ret = new StringBuffer("[");
		Iterator keys = map.keySet().iterator();
		while (keys.hasNext()) {
			key = keys.next();
			ret.append(key + ":" + map.get(key) + ",");
		}
		ret.setCharAt(ret.length() - 1, ']');
		return ret.toString();
	}

	/**
	 * @param args
	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//
//	}

}
